import 'package:flutter/material.dart';

import 'MainCart.dart';
import 'MainCategory.dart';
import 'MainHome.dart';
import 'MainMine.dart';

class WisdomShop extends StatefulWidget {
  const WisdomShop({super.key});

  @override
  State createState() => _WisdomShopState();
}

class _WisdomShopState extends State<WisdomShop> {
  int currentIndex = 0;

  List<BottomNavigationBarItem> barItemList() {
    List<BottomNavigationBarItem> items = [];
    items.add(
      BottomNavigationBarItem(
          icon: Image.asset(
            'tabbar/home.png',
            width: 32,
            height: 32,
          ),
          activeIcon: Image.asset(
            'tabbar/home-active.png',
            width: 32,
            height: 32,
          ),
          label: '首页'),
    );
    items.add(
      BottomNavigationBarItem(
          icon: Image.asset(
            'tabbar/cate.png',
            width: 32,
            height: 32,
          ),
          activeIcon: Image.asset(
            'tabbar/cate-active.png',
            width: 32,
            height: 32,
          ),
          label: '分类'),
    );
    items.add(
      BottomNavigationBarItem(
          icon: Image.asset(
            'tabbar/cart.png',
            width: 32,
            height: 32,
          ),
          activeIcon: Image.asset(
            'tabbar/cart-active.png',
            width: 32,
            height: 32,
          ),
          label: '购物车'),
    );
    items.add(
      BottomNavigationBarItem(
          icon: Image.asset(
            'tabbar/user.png',
            width: 32,
            height: 32,
          ),
          activeIcon: Image.asset(
            'tabbar/user-active.png',
            width: 32,
            height: 32,
          ),
          label: '我的'),
    );
    return items;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '智慧商城',
      home: Scaffold(
        body: SafeArea(
            child: IndexedStack(
          index: currentIndex,
          children: const [MainHome(), MainCategory(), MainCart(), MainMine()],
        )),
        bottomNavigationBar: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          items: barItemList(),
          currentIndex: currentIndex,
          selectedItemColor: Colors.red,
          unselectedItemColor: Colors.black,
          onTap: (int index) {
            setState(() {
              currentIndex = index;
            });
          },
        ),
      ),
    );
  }
}
